package com.hongxun.modules.bss.service.impl;

import java.util.UUID;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

import com.hongxun.modules.bss.dao.APBaseDao;
import com.hongxun.modules.bss.entity.APBaseEntity;
import com.hongxun.modules.bss.service.APBaseService;


@Service("aPBaseService")
public class APBaseServiceImpl implements APBaseService {
    @Autowired
    private APBaseDao aPBaseDao;

    @Override
    public APBaseEntity queryObject(String guid) {
        return aPBaseDao.queryObject(guid);
    }

    @Override
    public List<APBaseEntity> queryList(Map<String, Object> map) {
        return aPBaseDao.queryList(map);
    }

    @Override
    public int queryTotal(Map<String, Object> map) {
        return aPBaseDao.queryTotal(map);
    }

    @Override
    public void save(APBaseEntity aPBase) {
        if (aPBase.getGuid() == null || aPBase.getGuid().equals("")) {

            aPBase.setGuid(UUID.randomUUID().toString());
        }
        aPBaseDao.save(aPBase);
    }

    @Override
    public void update(APBaseEntity aPBase) {
        aPBaseDao.update(aPBase);
    }

    @Override
    public void delete(String guid) {
        aPBaseDao.delete(guid);
    }

    @Override
    public void deleteBatch(String[] guids) {
        aPBaseDao.deleteBatch(guids);
    }

    @Override
    public void insertOrReplaceOrDelete(APBaseEntity entities) {
        if (entities.getPBDatastate().equals("删除")) {
            aPBaseDao.delete(entities.getGuid());
        } else {
            APBaseEntity apBaseEntity = aPBaseDao.queryObject(entities.getGuid());
            if (apBaseEntity == null) {
                aPBaseDao.save(entities);
            } else {
                aPBaseDao.update(entities);
            }
        }
    }
}
